package com.demo.hadoop.conf;

import junit.framework.TestCase;

import org.apache.hadoop.conf.Configuration;
import org.junit.Test;

/**
 * @author nieyong
 * @time 2012-5-17
 * @version 1.0
 */
public class TestConfig extends TestCase {

	@Test
	public void testConfig() {
		Configuration conf = new Configuration();
		conf.addResource("configuration-1.xml");
		assertEquals(conf.get("color"), "yellow");
		assertEquals(conf.getInt("size", 0), 10);
		assertEquals(conf.get("breadth", "wide"), "wide");
	}

	@Test
	public void testConfig2() {
		Configuration conf = new Configuration();
		conf.addResource("configuration-1.xml");
		conf.addResource("configuration-2.xml");

		assertEquals(conf.get("color"), "yellow");
		assertEquals(conf.getInt("size", 0), 12);
		assertEquals(conf.get("breadth", "wide"), "wide");

		assertEquals(conf.get("size-weight"), "12,heavy");
	}

	@Test
	public void testConfig3() {
		Configuration conf = new Configuration();
		conf.addResource("configuration-1.xml");
		conf.addResource("configuration-2.xml");

		assertEquals(conf.get("color"), "yellow");
		assertEquals(conf.getInt("size", 0), 12);
		assertEquals(conf.get("breadth", "wide"), "wide");

		conf.set("size", "13");
		assertEquals(conf.get("size-weight"), "13,heavy");
	}

	@Test
	public void testConfig4() {
		Configuration conf = new Configuration();
		conf.addResource("configuration-1.xml");
		conf.addResource("configuration-2.xml");

		conf.set("length", "233");
		assertEquals(conf.get("length"), "233");

		System.setProperty("meme", "memvalue");
		assertEquals(conf.get("meme"), null);
	}
}
